package com.course.business.controller.admin;

import com.course.server.common.PageRequest;
import com.course.server.common.Result;
import com.course.server.dto.TeacherDto;
import com.course.server.service.TeacherService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * @author: Durian
 * @date: 2021/5/3 12:33
 */
@RestController
@RequestMapping("/admin/teachers")
public class TeacherController {

    public static final String BUSINESS_NAME = "讲师管理";

    @Resource
    private TeacherService teacherService;

    @GetMapping("/all")
    public Result listAll() {
        return Result.success(teacherService.listAll());
    }

    @GetMapping
    public Result list(@Validated PageRequest request) {
        return Result.success(teacherService.list(request.getPage(), request.getSize()));
    }

    @PostMapping
    public Result save(@RequestBody @Validated TeacherDto teacherDto) {
        teacherService.save(teacherDto);
        return Result.success();
    }

    @DeleteMapping("{teacherId}")
    public Result delete(@PathVariable("teacherId") @NotBlank(message = "待删除讲师ID不能为空") String teacherId) {
        teacherService.delete(teacherId);
        return Result.success();
    }
}
